﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Shapes;
using System.Windows.Threading;
using System.Windows.Controls;
using System.Windows.Media.Animation;
using System.Windows;

namespace Hugo
{
    class HandCursor
    {
        Rectangle hand;
        Canvas canvas;

        const int handSize = 50;

        public HandCursor(Canvas c)
        {
            hand = Util.getSymbol(Util.loadBitmap(Properties.Resources.Hand_Basic), handSize, handSize);
            hand.Name = "handCursor";
            c.RegisterName(hand.Name, hand);
            canvas = c;
            canvas.Children.Add(hand);

            startAppropriateTracker();
        }

        public void startAppropriateTracker()
        {
            if (GlobalSettings.isUsingKinect)
            {
                //new KinectCursorController(this);
            }
            else
            {
                new MouseCursorController(this);
            }
        }

        public double getXPosition()
        {
            return Canvas.GetLeft(hand);
        }

        public double getYPosition()
        {
            return Canvas.GetTop(hand);
        }

        public void setCursorPosition(double x, double y)
        {
            Canvas.SetLeft(hand, x - handSize / 2);
            Canvas.SetTop(hand, y - handSize / 2);
        }

        internal System.Windows.Point getPosition()
        {
            return new System.Windows.Point(getXPosition(), getYPosition());
        }

        internal void fadeOut()
        {
            DoubleAnimation myDoubleAnimation = AnimationFactory.getFadeOutAnimation();

                Storyboard myStoryboard = new Storyboard();
                myStoryboard.Children.Add(myDoubleAnimation);
                Storyboard.SetTargetName(myDoubleAnimation, hand.Name);
                Storyboard.SetTargetProperty(myDoubleAnimation, new PropertyPath(Canvas.OpacityProperty));

                myStoryboard.Begin(canvas);
        }

        internal void fadeIn()
        {
            DoubleAnimation myDoubleAnimation = AnimationFactory.getFadeInAnimation();

            Storyboard myStoryboard = new Storyboard();
            myStoryboard.Children.Add(myDoubleAnimation);
            Storyboard.SetTargetName(myDoubleAnimation, hand.Name);
            Storyboard.SetTargetProperty(myDoubleAnimation, new PropertyPath(Canvas.OpacityProperty));

            myStoryboard.Begin(canvas);
        }
    }
}
